wx-App({

  /**
   * 当小程序初始化完成时，会触发 onLaunch（全局只触发一次）
   */
  onLaunch: function () {
    
  },

  /**
   * 当小程序启动，或从后台进入前台显示，会触发 onShow
   */
  onShow: function (options) {
    
  },

  /**
   * 当小程序从前台进入后台，会触发 onHide
   */
  onHide: function () {
    
  },

  /**
   * 当小程序发生脚本错误，或者 api 调用失败时，会触发 onError 并带上错误信息
   */
  onError: function (msg) {
    
  },
  /**
   * 
   * @param {*} params  设置路径
   */
  onPageNotFound:function name(params) {
    
  },
  // 获取用户bid信息
  getUserBid:function(res){
    if(this.globalData.bid){
      res(this.globalData.bid);
      return;
    }
    var that = this;
    wx.request({
      url: 'http://www.jiuyunda.net:90/api/v1/city/current_city',
      data: {
        "province":that.globalData.city.province,
        "city":that.globalData.city.city,
        "district":that.globalData.city.district,
      },
      method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      // header: {}, // 设置请求的 header
      success: function(bid){
        that.globalData.bid = bid.data;
        res(bid.data);
      },
      fail: function() {
      },
      complete: function() {
      }
    })
  },
  // 获取位置信息
  getUserLocation:function(res){
   var that = this;
   if(this.globalData.location){
     res(this.globalData.location);
     return;
   }
    wx.getLocation({
      type: 'gcj02', // 默认为 wgs84 返回 gps 坐标，gcj02 返回可用于 wx.openLocation 的坐标
      success: function(location){
        that.globalData.location = location;
        res(that.globalData.location);
      },
      fail: function() {
        wx.showToast({
          title:"获取位置失败",
          icon:"success",
          duration:350
        })
      },
      complete: function() {
      }
    })
  },
  // 获取用户信息
  getUserInfo:function(cb){
    var that = this
    if(this.globalData.userInfo){
      typeof cb == "function" && cb(this.globalData.userInfo)
    }else{
      //调用登录接口
      wx.login({
        success: function () {
          wx.getUserInfo({
            success: function (res) {
              that.globalData.userInfo = res.userInfo
              typeof cb == "function" && cb(that.globalData.userInfo)
            }
          })
        }
      })
    }
  },
})
